package com.yonyou.crm.sys.defaul.ctrl;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.yonyou.crm.common.exception.CrmMessageException;

@Controller
public class DefaultCtrl {

	/**
	 * 路由请求
	 * @param request
	 * @return
	 * @throws CrmMessageException 
	 */
	@RequestMapping(value = {"/", "/login","/home", "/page/**"}, method = RequestMethod.GET)
	public String route(HttpServletRequest request,HttpServletResponse response) throws CrmMessageException {
		InputStream inStream = null;
		Properties pps = new Properties();
        try {
        	inStream = getClass().getClassLoader().getResourceAsStream("conf/application.properties");
			pps.load(inStream);
		} catch (Exception e) {
			throw new CrmMessageException("读取配置文件信息异常");
		}
        finally {
        	try {
        		inStream.close();
        	}
        	catch (IOException e) {
        		throw new CrmMessageException("关闭文件流异常");
        	}
        }
        response.addCookie(new Cookie("basedir", pps.getProperty("baseDir")));
		
		return "index";
	}
}
